﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpAnalyzer.Utilities;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace SharpAnalyzer.Collectors
{
    internal class TypeCollectorSyntaxWalker : CSharpSyntaxWalker
    {
        private readonly List<TypeDeclarationSyntax> types = new List<TypeDeclarationSyntax>();

        public TypeCollectorSyntaxWalker()
          : base(SyntaxWalkerDepth.Node)
        {
        }

        public IEnumerable<TypeDeclarationSyntax> GetTypes(SyntaxNode namespaceNode)
        {
            Verify.NotNull(() => namespaceNode);

            NamespaceDeclarationSyntax declarationSyntax = namespaceNode as NamespaceDeclarationSyntax;
            if (declarationSyntax != null)
                Visit(declarationSyntax);
            return types.AsReadOnly();
        }

        public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
        {
            base.VisitInterfaceDeclaration(node);
            types.Add(node);
        }

        public override void VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            base.VisitClassDeclaration(node);
            types.Add(node);
        }

        public override void VisitStructDeclaration(StructDeclarationSyntax node)
        {
            base.VisitStructDeclaration(node);
            types.Add(node);
        }
    }
}
